package com.cskaoyan.eighth.controller;

import com.cskaoyan.eighth.bean.InfoBean;
import com.cskaoyan.eighth.bean.BaseRespVo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/auth")
public class LoginController {

    @RequestMapping("/login")
    public BaseRespVo login(@RequestBody Map map){
        Object username = map.get("username");//演示如何获取json数据的
        Object password = map.get("password");//演示如何获取json数据的

        return BaseRespVo.ok("5db46a74-8184-4fb9-b2c9-037645faf2d5"); //响应结果
    }

    @RequestMapping("/info")
    public BaseRespVo info(String token){
        //Map data = new HashMap<String,Object>();
        //data.put("avatar",);
        //data.put("name",);
        //data.put("perms",);
        //data.put("roles",);
        //创建这个infobean的过程，应该是大家数据库查询的过程
        InfoBean infoBean = new InfoBean();
        infoBean.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        infoBean.setName("admin123");
        List<String> roles = new ArrayList<>();
        roles.add("超级管理员");
        List<String> perms = new ArrayList<>();
        perms.add("*");
        infoBean.setRoles(roles);
        infoBean.setPerms(perms);
        return BaseRespVo.ok(infoBean);
    }
}
